// 定义路由规则组件
import { Route,Redirect,Switch } from 'react-router-dom'
import React, { Component,lazy,Suspense } from 'react';
import Loading from '../components/Loading'
// lazy 方法,用于以路由懒加载的方式引入组件
// Suspense组件,用于应用对应的组件,并且提供loading加载,使用时,用它包裹对应要应用的组件即可

// Switch 包裹对应的路由规则,每次只能匹配一个路由规则,一般结合重定向Redirect组件和404组件使用

const login = lazy(() => import('../view/login/Login.jsx'))
// 引入其他组件...
const dashboard = lazy(() => import('../view/dashboard/Dashboard.jsx'))
class Index extends Component {
    render() {
        return (
            <>
                <Suspense fallback={<Loading></Loading>}>
                    <Switch>
                        <Route path='/login' component={login}></Route>
                        <Route path='/dashboard' component={dashboard}></Route>
                        <Redirect from='/' to='/login' exact></Redirect>
                    </Switch>
                </Suspense>
            </>
        );
    }
}

export default Index;
